import React from 'react';
import { InputNumber, DatePicker, Switch, Input } from 'antd';

const FilterValue = ({ value, dataType, onChange, size = 'default', showNumberControls = true }) => {
  const currentType = dataType?.type;

  const handleChange = (newValue) => {
    if (currentType === 'Integer' || currentType === 'Double') {
      if (newValue === '') {
        onChange(null);
        return;
      }
      onChange(Number(newValue));
      return;
    }
    onChange(newValue);
  };

  const renderInput = () => {
    switch (currentType) {
      case 'Integer':
        return (
          <InputNumber
            value={value}
            onChange={handleChange}
            controls={showNumberControls}
            controlsPosition="right"
            max={100000000}
            precision={0}
            size={size}
            placeholder="请输入"
            style={{ width: '100%' }}
          />
        );
      case 'Double':
        return (
          <InputNumber
            value={value}
            onChange={handleChange}
            controls={showNumberControls}
            controlsPosition="right"
            precision={2}
            size={size}
            placeholder="请输入"
            style={{ width: '100%' }}
          />
        );
      case 'Date':
        return (
          <DatePicker
            value={value}
            onChange={handleChange}
            size={size}
            style={{ width: '100%' }}
            format="YYYY-MM-DD"
          />
        );
      case 'Time':
        return (
          <DatePicker
            value={value}
            onChange={handleChange}
            size={size}
            style={{ width: '100%' }}
            showTime
            format="YYYY-MM-DD HH:mm:ss"
          />
        );
      case 'Boolean':
        return (
          <Switch
            checked={value}
            onChange={handleChange}
            size={size}
            style={{ width: 48 }}
            checkedChildren="是"
            unCheckedChildren="否"
          />
        );
      default:
        return (
          <Input
            value={value}
            onChange={(e) => handleChange(e.target.value)}
            size={size}
            placeholder="请输入"
          />
        );
    }
  };

  return <div className="filter-value">{renderInput()}</div>;
};

export default FilterValue; 